package com.longjianghuasheng.logistics.ext

import android.annotation.SuppressLint
import androidx.annotation.StringRes
import com.blankj.utilcode.util.RegexUtils
import com.longjianghuasheng.logistics.R
import com.xuexiang.xui.widget.toast.XToast
import me.hgj.jetpackmvvm.base.appContext


fun toastInfo(message: String) {
    XToast.info(appContext, message).show()
}

fun toastInfo(@StringRes message: Int) {
    XToast.info(appContext, message).show()
}

fun toastNormal(message: String) {
    XToast.normal(appContext, message).show()

}

fun toastNormal(@StringRes message: Int) {
    XToast.normal(appContext, message).show()
}

@SuppressLint("CheckResult")
fun toastError(message: String) {
    XToast.error(appContext, message).show()
}

fun toastError(@StringRes message: Int) {
    XToast.error(appContext, message).show()
}

@SuppressLint("CheckResult")
fun toastSuccess(@StringRes message: Int) {
    XToast.success(appContext, message).show()
}

fun toastSuccess(message: String) {
    XToast.success(appContext, message).show()
}

@SuppressLint("CheckResult")
fun toastWarning(@StringRes message: Int) {
    XToast.warning(appContext, message).show()
}

//校验手机号
fun checkPhone(phone: String?, isToast: Boolean = true): Boolean {
    var checkSuccess = false
    when {
        phone.isNullOrEmpty() -> {
            if (isToast) {
                toastNormal("请输入手机号")
            }
        }
        !RegexUtils.isMobileExact(phone) -> {
            if (isToast) {
            toastNormal("手机号有误")

            }
        }

        else -> checkSuccess = true
    }
    return checkSuccess
}

//校验邮箱
fun checkEmail(email: String?): Boolean {
    var checkSuccess = false
    when {
        email.isNullOrEmpty() -> toastWarning(R.string.toast_user_name_empty)
        !RegexUtils.isEmail(email) -> toastWarning(R.string.toast_user_name_error)
        else -> checkSuccess = true
    }
    return checkSuccess
}

//校验验证码
fun checkVerification(verification: String?): Boolean {
    var checkSuccess = false
    when {
        verification.isNullOrEmpty() -> toastNormal(R.string.toast_verification_empty)
//        !TextUtils.equals(
//            verification,
//            SPStaticUtils.getString(KEY_VERIFICATION_CODE)
//        ) -> toastWarning(R.string.toast_verification_error)
        else -> checkSuccess = true
    }
    return checkSuccess
}


//校验密码
fun checkPwd(pwd: String?): Boolean {
    var checkSuccess = false
    when {
        pwd.isNullOrEmpty() -> toastNormal(R.string.toast_password_empty)
        pwd.length !in 6..10 -> toastNormal(R.string.toast_password_error)
        else -> checkSuccess = true
    }
    return checkSuccess
}